package com.ruoyi.web.controller.service.impl;

import java.util.List;

import com.ruoyi.web.controller.demo.domain.CarList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.web.controller.demo.domain.SysWzxUser;
import com.ruoyi.web.controller.mapper.CarListMapper;
import com.ruoyi.web.controller.demo.domain.CarList;
import com.ruoyi.web.controller.service.ICarListService;
import com.ruoyi.common.core.text.Convert;

/**
 * 车辆列Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-25
 */
@Service
public class CarListServiceImpl implements ICarListService 
{
    @Autowired
    private CarListMapper carListMapper;

    /**
     * 查询车辆列
     * 
     * @param carId 车辆列主键
     * @return 车辆列
     */
    @Override
    public CarList selectCarListByCarId(Long carId)
    {
        return carListMapper.selectCarListByCarId(carId);
    }

    /**
     * 查询车辆列列表
     * 
     * @param carList 车辆列
     * @return 车辆列
     */
    @Override
    public List<CarList> selectCarListList(CarList carList)
    {
        return carListMapper.selectCarListList(carList);
    }

    /**
     * 新增车辆列
     * 
     * @param carList 车辆列
     * @return 结果
     */
    @Transactional
    @Override
    public int insertCarList(CarList carList)
    {
        int rows = carListMapper.insertCarList(carList);
        insertSysWzxUser(carList);
        return rows;
    }

    /**
     * 修改车辆列
     * 
     * @param carList 车辆列
     * @return 结果
     */
    @Transactional
    @Override
    public int updateCarList(CarList carList)
    {

        insertSysWzxUser(carList);
        return carListMapper.updateCarList(carList);
    }

    /**
     * 批量删除车辆列
     * 
     * @param carIds 需要删除的车辆列主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteCarListByCarIds(String carIds)
    {

        return carListMapper.deleteCarListByCarIds(Convert.toStrArray(carIds));
    }

    /**
     * 删除车辆列信息
     * 
     * @param carId 车辆列主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteCarListByCarId(Long carId)
    {

        return carListMapper.deleteCarListByCarId(carId);
    }

    @Override
    public int updateCarStatusNormal(Long carId) {
        return carListMapper.updateCarStatusNormal(carId);
    }

    @Override
    public int updateCarStatusSend(Long carId) {
        return carListMapper.updateCarStatusSend(carId);
    }

    /**
     * 新增人员信息信息
     * 
     * @param carList 车辆列对象
     */
    public void insertSysWzxUser(CarList carList)
    {
        List<SysWzxUser> sysWzxUserList = carList.getSysWzxUserList();
        Long carId = carList.getCarId();
        if (StringUtils.isNotNull(sysWzxUserList))
        {
            List<SysWzxUser> list = new ArrayList<SysWzxUser>();
            for (SysWzxUser sysWzxUser : sysWzxUserList)
            {
                sysWzxUser.setUserId(carId);
                list.add(sysWzxUser);
            }
            if (list.size() > 0)
            {
                carListMapper.batchSysWzxUser(list);
            }
        }
    }
}
